import java.util.Hashtable;
import java.util.Map;
import dao.anotacoes.*;

public aspect SingletonAvancadoComAnotacao{
    
    private Map singletons = new Hashtable();
    
    public interface SingletonInterno{}

    Object around() : call((@Singleton *).new(..)) 
    || call(* *.newInstance())
    {
        Object singleton = thisJoinPoint.getTarget();
        if(singleton == null)
            singleton = thisJoinPoint.getSignature().getDeclaringType();
        if(singletons.get(singleton)==null){
            singletons.put(singleton, proceed());
        }

        return singletons.get(singleton);
    }

    
}
